// pages/login/login.
import Toast from '@vant/weapp/toast/toast';
const {request} = require("../../utils/request");

Page({
  /**
   * 页面的初始数据
   */
  data: {
    phone:"183000",
    password:"1234567",
    phoneErr:'',
    passwordErr:''
  },
  onPhoneChange(e){
    console.log(e.detail);
    this.setData({
      phone:e.detail,
      phoneErr:e.detail?'':'不许为空'
    })
  },
  onPasswordChange(e){
    this.setData({
      password:e.detail,
      passwordErr:e.detail?'':'不许为空'
    })
  },
  onErr(){
    this.setData({
      msg:"手机号格式错误"
    })
  },
  async onLogin(){
    const r = await request({
      url: '/api/login',
      method:'post',
      data:{
        phone:this.data.phone,
        password:this.data.password,
      }});
      if(r.code==0){
        Toast.success("登录成功！");
        wx.setStorageSync('userinfo', r.info.r[0])
        setTimeout(()=>{
          wx.switchTab({
            url: '/pages/index/index',
          })
        },300)
      }
  }
})